/*
 * Command.h
 *
 *  Created on: May 12, 2011
 *      Author: Stijn, Bart, Dave
 */

#ifndef COMMAND_H_
#define COMMAND_H_

#include <vector>
#include <sstream>
#include <iostream>

#include <fcntl.h> // Open

#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>

#include "Commands.h"

class BuiltInCommand;

class Command {
	private:
		std::vector<std::string>* arguments;
		std::string ioInput;
		std::string ioOutput;
		bool append;
		bool isBackground;

		int priorityInc;
		bool executeCommand(const char*, char* const*, bool);

		int childPid;

	protected:
		std::string name;
		std::vector<std::string>* pathVariables;
		BuiltInCommand* builtInCommand;

		const char* expressions[COMMANDS_SIZE];

		std::string getCommandPath(std::string filename);
		bool fileExists(const char*);
		void executeBuiltInCommand(const char*, int, char* const*);

	public:
		Command(std::string, std::vector<std::string>*);
		virtual ~Command();

		bool isBuiltInCommand(const char*);
		std::string getName();
		void addArgument(std::string);
		std::vector<std::string>* getArguments();
		std::string getIOInput();
		void setIOInput(std::string);
		std::string getIOOutput();
		void setIOOutput(std::string);
		void setPriorityInc(int);
		bool getAppend();
		void setAppend(bool);
		void setBackground(bool);
		BuiltInCommand* getBuiltInCommmand();
		int getChildPid();

		bool virtual runCommand();
		bool virtual runCommand(bool);
};

#endif /* COMMAND_H_ */
